package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.summer.common.core.domain.R;
import org.summer.common.excel.utils.ExcelUtil;
import org.summer.common.log.annotation.Log;
import org.summer.common.log.enums.BusinessType;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.lawyer.domain.vo.accountapplication.AccountApplicationVo;
import org.summer.lawyer.domain.vo.accountapplication.ApplyExportVo;
import org.summer.lawyer.service.IAccountApplicationService;

import java.util.List;

/**
 *
 */
@Tag(name = "后台相关接口",description = "账号申请")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/apply")
public class ApplyController {

    private final IAccountApplicationService accountApplicationService;


    @Operation(description = "查询账号申请列表")
    @SaCheckPermission("account:apply:list")
    @GetMapping("/list")
    public TableDataInfo<AccountApplicationVo> list(AccountApplicationVo vo, PageQuery pageQuery) {
        return accountApplicationService.selectListPage(vo,pageQuery);

    }

    /**
     * 导出账号申请列表
     */
    @Operation(summary = "导出账号申请列表接口", description = "导出账号申请列表")
    @SaCheckPermission("account:apply:export")
    @Log(title = "账号申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AccountApplicationVo vo, HttpServletResponse response) {
        ExcelUtil.exportExcel(accountApplicationService.selectApplyExportVoList(vo), "账号申请", ApplyExportVo.class, response);
    }

    @Operation(description = "删除账号申请")
    @Log(title = "删除账号申请", businessType = BusinessType.DELETE)
    @SaCheckPermission("account:apply:remove")
    @DeleteMapping("/{ids}")
    public R<Void> removeApply(@NotEmpty(message = "主键不能为空")@PathVariable("ids")Long[] ids){
        accountApplicationService.deleteAccountApplicationByIds(List.of(ids));
        return R.ok();
    }

    @Operation(description = "获取账号申请信息")
    @SaCheckPermission("account:apply:query")
    @GetMapping("/{id}")
    public R<AccountApplicationVo> getInfo(@NotNull(message = "主键不能为空")@PathVariable("id")Long id){
        return R.ok(accountApplicationService.selectAccountApplicationVoById(id));

    }
}
